<%@ include file="/WEB-INF/pages/common/taglibs.jsp" %>
<%@ include file="/WEB-INF/pages/common/checkpermission.jsp" %>

<script type="text/javascript">
    function searchRecord() {
        var currentForm = document.forms["searchDeptForm"];
        currentForm.elements["searchTO.deptName"].value = currentForm.elements["searchTO.deptName"].value.trim();
        submitForm("searchDeptForm", "search.action");
    }

    function addRecord() {
        submitForm("searchDeptForm", "viewAdd.action");
    }

    function updateRecord(recordName) {
        var currentForm = document.forms["searchDeptForm"];
        currentForm.elements["deptModel.selectId"].value = recordName;
        submitForm("searchDeptForm", "view.action");
    }


    function deleteRecord() {
        if (!atLeastOneRecordChecked('searchDeptFormDiv')) {
            alert('<s:text name="label.select.atleast.one.record"/>');
        } else {
            if (window.confirm('<s:text name="label.confirm.delete"/>')) {
                submitForm("searchDeptForm", "delete.action");
            }
        }
    }

    function back() {
        submitForm("searchDeptForm", "../cases/clientSummary.action");
    }
</script>
<div id='searchDeptFormDiv'>
    <s:form name="searchDeptForm" action="">
        <s:hidden name="deptModel.selectId" value=""/>
        <table align="center" cellpadding="0" cellspacing="0" class="body_content full_width">
            <tr>
                <td align="left" valign="bottom" class="main_page_content_icon" width="4%">
                    <img src='<c:url value="/images/body-icon_check.gif"/>' width="29" height="44">
                </td>
                <td valign="bottom" class="page_title_bg" width="96%"><span class="page_title"><s:text
                        name="label.search.dept.title"/></span></td>
            </tr>
            <tr>
                <td class="subcontent">&nbsp;</td>
                <td class="subcontent">
                    <table class="sectionBorder" width="100%">
                        <tr>
                            <td class="form_label_padded" width="10%" nowrap><s:text name='label.deptName'/></td>
                            <td class="form_label_padded" width="2%">:</td>
                            <td class="txtData" align="left">
                                <s:textfield name="searchTO.deptName"/>
                            </td>
                        </tr>
                        <tr>
                            <td class="txtData" colspan="3">
                                <input type="button" class="button" value="<s:text name='label.search'/>"
                                       onclick="searchRecord();">
                                <input type="button" class="button" value="<s:text name='label.add'/>"
                                       onclick="addRecord();">
                                <input type="button" class="button" value="<s:text name='label.delete'/>"
                                       onclick="deleteRecord();">
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                <display:table name="helper" form="searchDeptForm" uid="row" action="search.action">
                                    <display:column titleKey="label.seq" width="3%">
                                        <s:property
                                                value="%{#attr.row_rowNum+(helper.pageNumber-1)*helper.objectsPerPage}"/>
                                    </display:column>
                                    <display:column width="2%">
                                        <s:checkbox name="resultList[%{#attr.row_rowNum-1}].selectId"
                                                    fieldValue="%{#attr.row.deptId}"/>
                                    </display:column>
                                    <display:column titleKey="label.deptName" sortable="true" sortProperty="DEPT_NAME"
                                                    width="95%">
                                        <a href="javascript:updateRecord('<s:property value="%{#attr.row.deptId}"/>')">
                                            <s:property value="%{#attr.row.deptName}"/> </a>
                                    </display:column>
                                </display:table>
                            </td>
                        </tr>
                        <tr>
                            <td class="txtData" align="left" width="100%" colspan="3">
                                <input type="button" class="button" value="<s:text name='label.back'/>" onclick="back();">
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>

        </table>
    </s:form>
</div>
